#include "gracesc.h"
#include <fstream.h>
#include <iostream>
#define BUFSIZE 512

namespace gracesc {
     //defines and end line in a graph
     void endl(XmgraceGraph& graph){
	  graph.newline=true;
     }
     //reads commands from a file (filename = file with commands)
     void read_command_file(const std::string &filename){
	  ifstream ifs (filename.c_str(), std::ios::in);    
	  if (ifs.fail()){
	       std::cerr << "Error(load commands): unable to open file(" << filename << ")" << std::endl;
	       exit(1);
	  }
	  char buffer[BUFSIZE];
	  while (!ifs.eof()){
	       ifs.getline(buffer, BUFSIZE);
	       GraceCommand(buffer);
	  }
	  ifs.close();
     }
     //loads a set of commands from a file with name filename
     void XmgraceGraph::load_commands(const std::string & filename){
	  GracePrintf("with g%d",graph_number);
	  read_command_file(filename);
     }
     //loads a set of commands from a file with name filename
     void Xmgrace::load_commands(const std::string & filename){
	  read_command_file(filename);
     }
     
}
